package com.zb777.shuzhilingxi.controller;


import com.zb777.shuzhilingxi.Pojo.dto.MistakenQuestionDTO;
import com.zb777.shuzhilingxi.Pojo.dto.MistakenQuestionListDTO;
import com.zb777.shuzhilingxi.Pojo.entity.MistakenQuestion;
import com.zb777.shuzhilingxi.Pojo.entity.MistakenQuestionList;
import com.zb777.shuzhilingxi.result.Result;
import com.zb777.shuzhilingxi.service.IMistakenQuestionService;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author redaiyu
 * @since 2025-07-12
 */
@RestController
@RequestMapping("/mistaken_question_service")
@Tag(name = "错题接口")
@Slf4j
public class MistakenQuestionController {

    @Autowired
    private IMistakenQuestionService mistakenQuestionService;

    @Schema(description = "创建错题")
    @PostMapping("/question/create")
    public Result saveMistakenQuestionlist(@RequestBody MistakenQuestionDTO mistakenQuestionDTO) {
        log.info("创建错题列表:{}",mistakenQuestionDTO);
        return mistakenQuestionService.saveMistakenQuestion(mistakenQuestionDTO);
    }
    @GetMapping("/question/list/{listId}")
    @Schema(description = "获取错题")
    public Result<List<MistakenQuestion>> selectMistakenQuestion(@PathVariable Integer listId) {
        log.info("获取错题列表:{}",listId);
        return mistakenQuestionService.selectMistakenQuestion(listId);
    }
    @PutMapping("/question/delete/{questionId}")
    @Schema(description = "删除错题")
    public Result deleteMistakenQuestionlist(@PathVariable(value = "questionId") Integer questionId) {
        log.info("删除错题:{}",questionId);
        return mistakenQuestionService.deleteMistakenQuestion(questionId);
    }
    @PutMapping("/question/edit/{questionId}")
    @Schema(description = "创建错题列表")
    public Result updateMistakenQuestionlist(
            @PathVariable(value = "questionId") Integer questionId
            ,@RequestBody MistakenQuestion mistakenQuestion) {
        log.info("编辑错题列表:{}",questionId);
        return mistakenQuestionService.updateMistakenQuestion(questionId, mistakenQuestion);
    }
    @PostMapping(value = "/question/update_answer/{questionId}",produces = "text/stream;charset=utf-8")
    @Schema(description = "更新错题答案")
    public Flux<String> updateMistakenQuestionAnswer(
            @PathVariable(value = "questionId") Integer questionId) {
        log.info("更新错题答案:{}",questionId);
        return mistakenQuestionService.updateMistakenQuestionAnswer(questionId);
    }
}
